<template>
  <IMApp v-if="uikitInit" />
</template>
<script lang="ts">
import IMApp from "./components/IMApp/index.vue";
import { IMUIKit } from "@xkit-yx/im-kit-ui";
import V2NIM, { V2NIMConst } from "nim-web-sdk-ng";
import { app } from "./main";
export default {
  name: "App",
  components: {
    IMApp,
  },
  data() {
    return {
      uikitInit: false,
    };
  },
  mounted() {
    const initOptions = {
      appkey: "", // 请填写你的appkey
      account: "", // 请填写你的account
      token: "",
    };
    const localOptions = {
      // 添加好友模式，默认需要验证
      addFriendNeedVerify: true,
      // 群组被邀请模式，默认不需要验证
      teamAgreeMode:
        //@ts-ignore
        V2NIMConst.V2NIMTeamAgreeMode.V2NIM_TEAM_AGREE_MODE_NO_AUTH,
      // 单聊消息是否显示已读未读 默认 false
      p2pMsgReceiptVisible: true,
      // 群聊消息是否显示已读未读 默认 false
      teamMsgReceiptVisible: true,
      // 是否需要@消息 默认 true
      needMention: true,
      // 是否显示在线离线状态 默认 true
      loginStateVisible: true,
      // 是否允许转让群主
      allowTransferTeamOwner: true,
    };

    // 初始化 IM SDK 实例
    const nim = V2NIM.getInstance({
      appkey: initOptions.appkey,
      account: initOptions.account,
      token: initOptions.token,
      debugLevel: "debug",
      apiVersion: "v2",
    });

    // IM 连接
    nim.V2NIMLoginService.login(initOptions.account, initOptions.token, {
      retryCount: 5,
    });

    // 初始化 UIKit 实例
    app.config.globalProperties.$uikit = new IMUIKit({
      nim,
      singleton: true,
      localOptions,
    });
    if (app.config.globalProperties.$uikit) {
      this.uikitInit = true;
    }
  },
};
</script>
